package com.platform.service.impl;

import com.platform.annotation.SysLog;
import com.platform.common.ServerResponse;
import com.platform.dao.UserRoleMapper;
import com.platform.pojo.UserRole;
import com.platform.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("iUserRoleService")
public class UserRoleServiceImpl implements IUserRoleService {
    @Autowired
    private UserRoleMapper userRoleMapper;

    @SysLog("新增用户角色")
    public ServerResponse<String> insert(UserRole userRole){
        int countResult = userRoleMapper.insert(userRole);
        if(0 < countResult){
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    @SysLog("删除用户角色")
    public ServerResponse<String> del(Integer id){
        int countResult = userRoleMapper.deleteByPrimaryKey(id);
        if(0 < countResult){
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    /**
     * 根据用户登录名查询角色编码集合
     * @param userName
     * @return
     */
    @SysLog("查询用户已有权限")
    public ServerResponse<List<String>> selectByUserName(String userName){
        List<String> stringList = userRoleMapper.selectByUserName(userName);
        if(null != stringList && 0 < stringList.size()){
            return ServerResponse.createBySuccess("查询成功",stringList);
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }

}
